﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NUS.ISS.ARS.Web.PageController;
using NUS.ISS.ARS.Common;
using NUS.ISS.ARS.BusinessEntity;
namespace NUS.ISS.ARS.Web.Booking
{
    public partial class ContractInfo : BookingBaseController
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            CurrentPage = "ContractInfo.aspx";
            base.Page_Load(sender, e);

            if (!IsPostBack)
            {
                btnPre.Visible = IsPrePageVisible;
                btnNext.Visible = IsNextPageVisible;
                InitialPage();
            }
        }

        private void InitialPage()
        {
            if (ReservationData.Contact != null)
            {
                ddlTitle.SelectedValue = ReservationData.Contact.Gender.ToString();
                txtGivenName.Text = ReservationData.Contact.FirstName;
                txtSurName.Text = ReservationData.Contact.LastName;
                txtContractNumber.Text = ReservationData.Contact.ContactNumber;
                txtEmail.Text = ReservationData.Contact.Email;
            }
        }

        protected void btnNext_Click(object sender, EventArgs e)
        {
            SaveToSession();
            MoveToNextPage();
        }

        private void SaveToSession()
        {
            Customer customer = new Customer()
            {
                Gender = (Byte)Int32.Parse(ddlTitle.SelectedValue),
                FirstName = txtGivenName.Text.Trim(),
                LastName = txtSurName.Text.Trim(),
                ContactNumber = txtContractNumber.Text.Trim(),
                Email = txtEmail.Text.Trim()
            };

            ReservationData.Contact = customer;
        }

        protected void btnPre_Click(object sender, EventArgs e)
        {
            MoveToPrePage();
        }
    }
}